home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Resources / General / ProNET / src / utilities / pronet-start.c < prev    next >
C/C++ Source or Header  |  1997-01-01  |  4KB  |  140 lines

  1. /*
  2.     pronet-start.c
  3.  
  4.     ProNET Quickstart. Prior to V3, you had to create MountLists and other
  5.     config files to get ProNET started. Now it's much more easy!!
  6.  
  7. */
  8.  
  9. #include <string.h>
  10.  
  11. #include <exec/execbase.h>
  12. #include <dos/dos.h>
  13. #include <dos/filehandler.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17.  
  18. void __chkabort(void) {}    /* Disable CTRL-C handling */
  19. ULONG __nocommandline = 0;
  20.  
  21. char template[]="LOCALNAME/A,REMOTENAME/A,UNIT/N,UNIQUE/S";
  22. LONG array[4];
  23. char handlername[]="l:pronet-handler";
  24.  
  25. char versiontag[] = "$VER: pronet-start 37.0 (30.11.96)";
  26.  
  27. struct RDArgs* rdargs;
  28. struct DosEnvec* environment;
  29. struct FileSysStartupMsg* fssm;
  30. UBYTE *strbuf;
  31. struct DeviceNode* dosentry;
  32. char faultbuf[60];
  33.  
  34. char newarray0[20];
  35.  
  36. int main()
  37. {
  38.     ULONG result,i;
  39.     char k;
  40.  
  41.     if(rdargs = ReadArgs(template,&array[0],NULL))
  42.     {
  43.         if(array[2]) array[2]=*((ULONG*)array[2]);
  44.  
  45.         if(fssm = AllocVec(sizeof(struct FileSysStartupMsg),MEMF_PUBLIC|MEMF_CLEAR))
  46.         {
  47.             if(environment = AllocVec(sizeof(struct DosEnvec),MEMF_PUBLIC|MEMF_CLEAR))
  48.             {
  49.                 if(strbuf = AllocVec(128,MEMF_PUBLIC|MEMF_CLEAR))
  50.                 {
  51.                     environment->de_TableSize = 19;
  52.                     environment->de_Surfaces = 1;
  53.                     environment->de_SectorPerBlock = 1;
  54.                     environment->de_BlocksPerTrack = 1;
  55.                     environment->de_DosType = ID_DOS_DISK;
  56.                     if(array[3]) environment->de_HighCyl = 1;
  57.  
  58.                     fssm->fssm_Unit = array[2];
  59.                     fssm->fssm_Environ = MKBADDR(environment);
  60.                     /* We want a BCPL string! */
  61.                     strcpy(strbuf+1,(const char*)array[1]);
  62.                     strbuf[0] = strlen((char*)array[1]);
  63.                     fssm->fssm_Device = MKBADDR(strbuf);
  64.  
  65.                     /* Convert local name to uppercase */
  66.                     for(i=0 ; i<18 && ((char*)array[0])[i]!='\0' ; i++)
  67.                     {
  68.                         k=((char*)array[0])[i];
  69.                         newarray0[i] = (k>='a'&&k<='z' ? k-32 : k);
  70.                     }
  71.                     newarray0[i]='\0';
  72.  
  73.                     if(dosentry = (struct DeviceNode*)MakeDosEntry(newarray0,DLT_DEVICE))
  74.                     {
  75.                         strcpy(strbuf+65,(const char*)handlername);
  76.                         strbuf[64] = strlen(handlername);
  77.                         dosentry->dn_Handler = MKBADDR(strbuf+64);
  78.                         dosentry->dn_StackSize = 4096;
  79.                         dosentry->dn_Priority = 10;
  80.                         dosentry->dn_Startup = MKBADDR(fssm);
  81.                         dosentry->dn_GlobalVec = -1;
  82.  
  83.                         /* Add our device to the dos list */
  84.                         if(AddDosEntry((struct DosList*)dosentry))
  85.                         {
  86.                             /* ... and start it up! */
  87.                             strcat(newarray0,":");
  88.                             if(DeviceProc(newarray0))
  89.                             {
  90.                                 /* Printf("Installed local `%s:', linked to `%s:' on unit %ld.\n",array[0],array[1],array[2]); */
  91.                                 FreeArgs(rdargs);
  92.                                 return(0);
  93.                             }
  94.                             else
  95.                             {
  96.                                 switch(result=IoErr())
  97.                                 {
  98.                                     case 1000003:
  99.                                         Printf("Device `%s:' on unit %ld doesn't exist.\n",array[1],array[2]);
  100.                                         break;
  101.  
  102.                                     case 1000002:
  103.                                         Printf("Couldn't open pronet.device.\n");
  104.                                         break;
  105.  
  106.                                     case 1000001:
  107.                                         Printf("Driver trouble: %s\n",(ULONG)strbuf);
  108.                                         break;
  109.  
  110.                                     case 1000000:
  111.                                         Printf("Unit %ld not defined.\n",array[2]);
  112.                                         break;
  113.  
  114.                                     default:
  115.                                         Fault(result,NULL,faultbuf,60);
  116.                                         Printf("%s\n",(ULONG)faultbuf);
  117.                                 }
  118.  
  119.                                 LockDosList(LDF_DEVICES|LDF_WRITE);
  120.                                 RemDosEntry((struct DosList*)dosentry);
  121.                                 UnLockDosList(LDF_DEVICES|LDF_WRITE);
  122.                                 SetIoErr(0);
  123.                             }
  124.                         }
  125.  
  126.                         FreeDosEntry((struct DosList*)dosentry);
  127.                     }
  128.                     FreeVec(strbuf);
  129.                 }
  130.                 FreeVec(environment);
  131.             }
  132.             FreeVec(fssm);
  133.         }
  134.         FreeArgs(rdargs);
  135.     }
  136.  
  137.     PrintFault(IoErr(),NULL);
  138.     return(20);
  139. }
  140.